<template>
  <div>
    <h1>gege</h1>
    <h1>{{ count }}</h1>
    <button @click="add">累加</button>
    <button @click="byebye">bye</button>
  </div>
</template>

<script>
import Pubsub from "pubsub-js";

export default {
  name: "Gege",
  data() {
    return {
      count: 0,
    };
  },
  methods: {
    add() {
      this.count++;

      //发送数据
      Pubsub.publish("count", this.count);
    },

    //取消订阅
    byebye() {
      //unsubscribe参数如果是订阅名称,则直接取消当前名称的所有订阅
      Pubsub.unsubscribe("count");
    },
  },
};
</script>

<style>
</style>